﻿using System.Security.Cryptography;
using System.Text;

string asdasd = "-50";
Console.WriteLine( 51+ Convert.ToInt32(asdasd));

Console.WriteLine("执行完成");



void MyCode(string log_info)
{
    log_info = "\r\n" + log_info;
    string folder = "F:\\My_Code";
    if (!Directory.Exists(folder))
    {
        Directory.CreateDirectory(folder);//目录不存在则创建相应的目录
    }

    string file_name = folder + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

    if (File.Exists(file_name))
    {
        FileStream fs = new FileStream(file_name, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
        StreamWriter sr = new StreamWriter(fs);
        sr.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "\t" + log_info);

        sr.Close();
        fs.Close();
    }
    else
    {
        FileStream fs = new FileStream(file_name, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
        StreamWriter sr = new StreamWriter(fs);
        sr.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "\t" + log_info);

        sr.Close();
        fs.Close();
    }
}
/// <summary>
/// Aes加密
/// </summary>
/// <param name="source">源字符串</param>
/// <param name="key">aes密钥，长度必须32位</param>
/// <returns>加密后的字符串</returns>
static string AesEncrypt(string str, string AesKey)
{
    try
    {
        if (string.IsNullOrEmpty(str)) return null;
        Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);

        RijndaelManaged rm = new RijndaelManaged
        {
            Key = Encoding.UTF8.GetBytes(AesKey),
            Mode = CipherMode.ECB,
            Padding = PaddingMode.PKCS7
        };

        ICryptoTransform cTransform = rm.CreateEncryptor();
        Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
        return Convert.ToBase64String(resultArray);
    }
    catch (Exception ex)
    {
        return null;
    }
}
/// <summary>
/// Aes解密
/// </summary>
/// <param name="source">源字符串</param>
/// <param name="key">aes密钥，长度必须32位</param>
/// <returns>解密后的字符串</returns>
static string AesDecrypt(string str, string AesKey)
{
    try
    {
        if (string.IsNullOrEmpty(str)) return null;
        str = str.Replace(" ", "+");
        Byte[] toEncryptArray = Convert.FromBase64String(str);

        RijndaelManaged rm = new RijndaelManaged
        {
            Key = Encoding.UTF8.GetBytes(AesKey),
            Mode = CipherMode.ECB,
            Padding = PaddingMode.PKCS7
        };

        ICryptoTransform cTransform = rm.CreateDecryptor();
        Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

        return Encoding.UTF8.GetString(resultArray);
    }
    catch (Exception e)
    {
        return "";
    }
}
